package com.firefly.service.query.shop;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.firefly.dao.dao.shop.po.AreaPo;
import com.firefly.dao.dao.shop.service.AreaService;
import com.firefly.dao.vo.CommonListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2023/2/1
 **/
@Service
public class AreaQuery {
    private final AreaService areaService;
    @Autowired
    public AreaQuery(AreaService areaService){
        this.areaService = areaService;
    }
    public CommonListVo getList(int parentId){
        QueryWrapper<AreaPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id",parentId);
        CommonListVo result = new CommonListVo();
        result.setList(areaService.list(queryWrapper));
        result.setCount(areaService.count(queryWrapper));
        return result;
    }
    // 获取所有可显示的地区
    public CommonListVo getDisplayList(int parentId){
        QueryWrapper<AreaPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id",parentId).eq("display",1);
        CommonListVo result = new CommonListVo();
        result.setList(areaService.list(queryWrapper));
        result.setCount(areaService.count(queryWrapper));
        return result;
    }
}
